﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Baosight.Platform.Core;
using Baosight.Platform.Core.UI.Controls;
using Baosight.Platform.Core.ServiceModel;
using Baosight.Platform.Core.UI;
using Telerik.Windows.Controls;
using Microsoft.Practices.Unity;
using Baosight.ZNH.ZMCA.UI.Controls;
using System.Windows.Data;
using Baosight.Platform.Core.UI;
using Baosight.Platform.Core.ServiceModel;
using Microsoft.Practices.Unity;
using Baosight.ZNH.ZMCA.UI.Utils;
using Baosight.ZNH.ZMCA.UI.PopWindows;
using Baosight.ZNH.ZMCommon.ChildWindows;
using Baosight.ZNH.ZMCA.UI.Model;

namespace Baosight.ZNH.ZMCA.UI
{
    /// <summary>
    /// 工作指示查询页面
    /// </summary>
    public partial class ZMCA50 : EFView
    {
        public EIBlock blockUser = null;
        public EIBlock blockClass = null;
        public event EventHandler DataChanged;
        public ZMCA50()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(ZMCA50_Loaded);
        }

        private void ZMCA50_Loaded(object sender, RoutedEventArgs e)
        {
            EIInfo eiInfo = new EIInfo();
            eiInfo.Set("service", "ZMCA50");
            eiInfo.Set("method", "initQuery");

            HttpServiceAgent agent = new HttpServiceAgent();
            agent.CallService(eiInfo, onInitLoadCompleted);
        }

        private void onInitLoadCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            blockUser = e.EIInfo.GetBlock("cmes.cp.people");
            blockClass = e.EIInfo.GetBlock("ProblemType");
        }

        public void OnQueryButtonClick(object sender, RoutedEventArgs e)
        {
            grid.Refresh();
        }

        private void AddColumnToBlock(EIBlock block, string colName, EIRow row, object colValue)
        {
            EIColumn column = new EIColumn();
            column.SetName(colName);
            row.Add(colName, colValue);
            block.AddColumn(column);
        }

        public void OnShowButtonClick(object sender, RoutedEventArgs e)
        {
            if (grid.GetCheckedEIRows().Count != 1)
            {
                EFWindow.Alert("请选择一条记录进行查看");
                return;
            }

            List<EIRow> list = grid.GetCheckedEIRows();
            EventHandler functions = null;

          
            Instruction selInstruction = new Instruction();
            selInstruction.FdCheckContent      = Common.GetStringValue(list[0]["fdCheckContent"]);
            selInstruction.FdFeedbackPersonId  = Common.GetStringValue(list[0]["fdFeedbackPersonId"]);
            selInstruction.FdCheckpersonId     = Common.GetStringValue(list[0]["fdCheckpersonId"]);
            selInstruction.FdCheckTime         = Common.GetStringValue(list[0]["fdCheckTime"]);
            selInstruction.FdKeyId             = Common.GetStringValue(list[0]["fdKeyId"]);
            selInstruction.FdProblemId         = Common.GetStringValue(list[0]["fdProblemId"]);
            selInstruction.FdProblemTypeId     = Common.GetStringValue(list[0]["fdProblemTypeId"]);
            selInstruction.FdStatus            = Common.GetStringValue(list[0]["fdStatus"]);
            selInstruction.FdFeedbackTime      = Common.GetStringValue(list[0]["fdFeedbackTime"]);
            selInstruction.FdFeedbackContent   = Common.GetStringValue(list[0]["fdFeedbackContent"]);
            //   ZMCASpecialCommon.ShowPopwindows("4", keyId, content_DataChanged, true);         

            CmesWindows window = new CmesWindows();
            window.Header = "查看";
            ZMCA45 content45 = new ZMCA45();
            content45.blockUser = blockUser;
            content45.blockClass = blockClass;
            content45.SetInstructionValue(selInstruction);
          
            window.Content = content45;
            
            window.ShowDialog();              

       /*     ZMCASpecialCommon.ShowPopwindows(list[0]["fdProblemTypeId"].ToString(), 
                list[0]["fdProblemId"].ToString(),functions ,false );*/
        }

        void content_SaveSuccess(object sender, EventArgs e)
        {
            //if (DataChanged != null)
            //{
            //    DataChanged(sender, e);
            //  //  grid.Refresh();
            //}
            grid.Refresh();
        }


        public void OnIndicationButtonClick(object sender, RoutedEventArgs e)
        {
            EFWindow window = new EFWindow();
            window.Header = "下达工作指示";
            ZMCA45 content = new ZMCA45();
          
        //    if (grid.GetCheckedEIRows().Count != 1)
      //      {
      //          EFWindow.Alert("请选择一条记录对应的问题进行指示");
    
   //             return;
     //       }
            //           content.fdKeyId.Value = grid.CheckedEIRows[0]["fdProblemId"];
            //           content.fdProblemTypeId.Value = grid.CheckedEIRows[0]["fdProblemTypeId"];
            content.fdKeyId.Value = null;
            content.fdProblemTypeId.Value = null;
            content.SetNew();
            content.SaveSuccess += new EventHandler(content_SaveSuccess);
            content.ZMCA45_Loaded(sender, e);
            window.Content = content;
            window.ShowDialog();
        }
    }
}
